﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;

namespace XbdSoft.WPFVersion
{
    /// <summary>
    /// Interaction logic for GlassMainWindow.xaml
    /// </summary>
    public partial class GlassMainWindow : Window
    {
        public GlassMainWindow()
        {
            InitializeComponent();
        }

        
        #region Set Window Long. Only run .NET 3.5. The reason hasn't been found

        const int GWL_STYLE = -16;
        const long WS_POPUP = 0x80000000;
        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, long dwNewLong);

        private void SetWindowLong()
        {
            Background = new SolidColorBrush(Colors.LightGray);
            WindowStyle = System.Windows.WindowStyle.None;
            IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            SetWindowLong(hWnd,GWL_STYLE,WS_POPUP); 
        }
        #endregion
        
        private WindowState lastWindowState;
         
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {             
            //SetWindowLong();  
            InfoWebBrowser.Navigate(new Uri("Http://xbd61.com",UriKind.Absolute)); 
        }
         

        #region Mouse Move on the Header of window
        public void DragWindow(object sender, MouseButtonEventArgs args)
        {
            this.DragMove();
        }

        #endregion

        #region Close
        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        #endregion

        #region Notify Icon Events
        private void OnNotifyIconDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
				ShowWindow();
            }
        }

        private void OnOpenClick(object sender, RoutedEventArgs e)
        {
			ShowWindow();
        }

        private void OnHideClick(object sender, RoutedEventArgs e)
        {
			HideWindow();
        }

        private void OnExitClick(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void MinButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
			HideWindow();
        }
 
		private void ShowWindow()
		{
                this.Show();
                InfoWebBrowser.UpdateLayout();
                this.WindowState = this.lastWindowState;
		}
		private void HideWindow()
		{
            this.lastWindowState = this.WindowState;
            this.Hide();
		}
 
        #endregion
         
        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MainTabControl.SelectedItem == InfoTabItem)
            {
                InfoWebBrowser.UpdateLayout();
            }
        }

    }
}
